import { Router } from 'express';
import dataSourceController from '@controllers/datasource.controller';

const router = Router();

/**
 * @route   GET /api/datasources/types
 * @desc    获取支持的数据源类型
 * @access  Private
 */
router.get('/types', dataSourceController.getDataSourceTypes.bind(dataSourceController));

/**
 * @route   POST /api/datasources/sync
 * @desc    同步所有数据源
 * @access  Private
 */
router.post('/sync', dataSourceController.syncAllDataSources.bind(dataSourceController));

/**
 * @route   GET /api/datasources
 * @desc    获取所有数据源
 * @access  Private
 * @query   type, status, enabled
 */
router.get('/', dataSourceController.getAllDataSources.bind(dataSourceController));

/**
 * @route   POST /api/datasources
 * @desc    创建数据源
 * @access  Private
 */
router.post('/', dataSourceController.createDataSource.bind(dataSourceController));

/**
 * @route   GET /api/datasources/:id
 * @desc    获取单个数据源
 * @access  Private
 */
router.get('/:id', dataSourceController.getDataSource.bind(dataSourceController));

/**
 * @route   PUT /api/datasources/:id
 * @desc    更新数据源
 * @access  Private
 */
router.put('/:id', dataSourceController.updateDataSource.bind(dataSourceController));

/**
 * @route   DELETE /api/datasources/:id
 * @desc    删除数据源
 * @access  Private
 */
router.delete('/:id', dataSourceController.deleteDataSource.bind(dataSourceController));

/**
 * @route   POST /api/datasources/:id/test
 * @desc    测试数据源连接
 * @access  Private
 */
router.post('/:id/test', dataSourceController.testDataSource.bind(dataSourceController));

/**
 * @route   PATCH /api/datasources/:id/toggle
 * @desc    启用/禁用数据源
 * @access  Private
 */
router.patch('/:id/toggle', dataSourceController.toggleDataSource.bind(dataSourceController));

/**
 * @route   GET /api/datasources/:id/stats
 * @desc    获取数据源统计信息
 * @access  Private
 */
router.get('/:id/stats', dataSourceController.getDataSourceStats.bind(dataSourceController));

/**
 * @route   GET /api/datasources/:id/alerts
 * @desc    从指定数据源获取告警
 * @access  Private
 */
router.get('/:id/alerts', dataSourceController.fetchAlertsFromSource.bind(dataSourceController));

export default router;
